import { Nodes } from '@knno/dom';
import { icon } from '../components/icon/icon';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, isStr, jsxBuild } from './utils';

export type UIIcon = Nodes;

interface IconProps extends JSXProps<UIIcon> {
	icon: string;
	size?: string;
	color?: string;
}

const ATTRS: AttrCheck = {
	icon: isStr,
	size: isStr,
	color: isStr,
};

export function Icon(props: IconProps, children: Nodes[]): UIIcon {
	return jsxBuild(
		icon(props.icon),
		Object.fromEntries(Object.entries(props).filter((v) => v[0] !== 'icon')),
		children,
		ATTRS
	);
}
